package com.profgj.profgj.enums;

/**
 * 当量计算类
 */
public class CalculatedValue {


    /**
     * 电力基数 *0.1229/1000
     */
    public static Double ELECTRICITY_STANDARD_COAL = 0.1229;
    public static Double ELECTRICITY_BASE = 1000.00;

    /**
     * 煤炭基数 *5051/7000
     */
    public static Double COAL_STANDARD_COAL = 5051.00;
    public static Double COAL_BASE = 7000.00;

    /**
     * 天然气基数   *1.33/1000
     */
    public static Double NATURAL_GAS_STANDARD_COAL = 1.33;
    public static Double NATURAL_GAS_BASE = 1000.00;

    /**
     * 燃料油基数   *0.8*1.4286/1000
     */
    public static Double FUEL_OIL_STANDARD_COAL = 0.8*1.4286;
    public static Double FUEL_OIL_BASE = 1000.00;

    /**
     * 水基数 *0.2571/1000
     */
    public static Double WATER_STANDARD_COAL = 0.2571;
    public static Double WATER_BASE = 1000.00;

    /**
     * 电力转换成标准煤炭
     * @param electricity   电力
     * @return
     */
    public static Integer electricityConvStandardCoal(Long electricity){
        return new Double(electricity * ELECTRICITY_STANDARD_COAL / ELECTRICITY_BASE).intValue();
    }

    /**
     * 煤转换标准煤炭
     * @param coal  煤
     * @return
     */
    public static Double coalConvStandardCoal(Double coal){

        // 保留2位小数处理
        return saveNumber2(coal * COAL_STANDARD_COAL / COAL_BASE);
    }

    /**
     * 天然气转换标准煤炭
     * @param naturalgas    天然气
     * @return
     */
    public static Double naturalgasConvStandardCoal(Double naturalgas){

        // 保留2位小数处理
        return saveNumber2(naturalgas * NATURAL_GAS_STANDARD_COAL / NATURAL_GAS_BASE);
    }

    /**
     * 燃料油转换标准煤炭
     * @param fueloil   燃料油
     * @return
     */
    public static Double fueloilConvStandardCoal(Double fueloil){

        // 保留2位小数处理
        return saveNumber2(fueloil * FUEL_OIL_STANDARD_COAL / FUEL_OIL_BASE);
    }

    /**
     * 水转换标准煤炭
     * @param water     水
     * @return
     */
    public static Double waterConvStandardCoal(Double water){

        // 处理保留2位小数
        return saveNumber2(water * WATER_STANDARD_COAL / WATER_BASE);
    }



    /**
     * 四舍五入保留小数位2位
     * @param num
     * @return
     */
    private static double saveNumber2(double num){

        return (double)(Math.round(num * 100))/100;
    }

    /**
     * 四舍五入保留小数位5位
     * @param num
     * @return
     */
    private static double saveNumber5(double num){

        return (double)(Math.round(num*100000))/100000;
    }


    /**
     * 判断是否有小数位
     * @param num
     * @return
     */
    private static boolean judgeIsDecimal(String num){
        boolean isdecimal = false;

        if (num.contains(".")) {
            isdecimal=true;
        }
        return isdecimal;
    }


    /**
     * 取小数位 位数
     * @param ver
     * @return
     */
    private static int pointNumber(double ver) {

        ver = 123.321;
        // 将浮点数转变成字符串
        String str = String.valueOf(ver);
        // 切割字符串
        String[] arr = str.split("\\.");
        // 获取小数点后字符串长度
        return arr[1].length();
    }

}
